// JavaScript Document


/**
 * Sidebar <div> made a GControl()
 */
function sideBlockControl(opt_options){
  this.opts = opt_options||{};
}

function refocus(){
  if(myBlock.isVisible)
  {
    pnt = virtualCenter(map.getCenter(),400);//sideBlock width
    map.setFocus(pnt);
  }else{
    map.setFocus(); //reset
  }
}

sideBlockControl.prototype = new GControl();
sideBlockControl.prototype.initialize = function(_map) {
  openText = this.opts.openText||"Sidebar";

  openerExterno =  createElem("sideblock-openExt");
  with (openerExterno.style) {
  	border = "1px solid black";
	position = "relative";
    top = "7px";
    left = "73px";
    width = "85px";
  }  
  opener = createElem("sideblock-open",openText); // open button
  with (opener.style) {
  	borderRight = "1px solid #B0B0B0";
  	borderBottom = "1px solid #B0B0B0";
  	paddingTop = "1px";
  	paddingLeft = "4px";
    textAlign = "left";
    fontSize = "12px";
    fontFamily = "Arial";
    fontWeight = "Bold";
    background = "#FFFFFF";
	width = "80px"
    cursor = "pointer";
  }
  openerExterno.appendChild(opener);
  
  /*opener = createElem("sideblock-open",openText); // open button
  opener.style.border = "1px solid black";
  opener.style.textAlign = "center";
  opener.style.fontSize = "12px";
  opener.style.fontFamily = "Arial";
  opener.style.backgroundColor = "#fff";
  opener.style.width = "65px";
  opener.style.position = "relative";
  opener.style.top = "7px";
  opener.style.left = "73px";
  opener.style.cursor = "pointer";*/
  
  _map.getContainer().appendChild(openerExterno);
  headerCont = createElem("sideblock-header"); // header contenedor del titulo y del close button
  headerCont.style.textAlign = "left";
  titleBlockText = this.opts.titleBar||"Titulo";
  titleBlock = createElem("sideblock-title",titleBlockText,"span");
  //header.appendChild(titleBlock);
  PanelTabImg = createElem("PanelTabImg");
  headerCont.appendChild(PanelTabImg);
  PanelTabImg.appendChild(titleBlock);
  closeDiv = createElem("sideblock-close-div");
  closeText = this.opts.closeText||"[x]&nbsp;";
  close = createElem("sideblock-close",closeText,"span"); // close button
  close.style.cursor = "pointer";
  closeDiv.appendChild(close);
  headerCont.appendChild(closeDiv);
  leftBar = createElem("sideblock"); // the parent element of the sidebar
  leftBar.appendChild(headerCont);
  _map.getContainer().appendChild(leftBar);
  leftBar.style.width = this.opts.sideBlockWidth||"400px";
  leftBar.style.height = this.opts.sideBlockHeight||"230px";
  contents = createElem("sideblock-container"); //contents div
  leftBar.appendChild(contents);
  contents.style.height = "90%";
  contents.style.overflow = "auto";
  var me = this;
  me.container = contents;
  me.isVisible = true;
  function openEvent(){me.isVisible=true; monitorActivoFlag=true; GEvent.trigger(me,'open',true)};
  function closeEvent(){me.isVisible=false; monitorActivoFlag=false; GEvent.trigger(me,'close',false)};
  me.show = function(){leftBar.style.display = "block"; openEvent()};
  me.hide = function(){leftBar.style.display = "none"; closeEvent()};
  close.onclick = function(){me.hide()};
  opener.onclick = function(){me.show(); me.alertar(false);};
  return leftBar;
}

sideBlockControl.prototype.alertar = function(state) {
	if (state){
		opener.style.color = "#FF0000";
		opener.style.textDecoration = "blink";
		}
	else {
		opener.style.color = "#000000";
		opener.style.textDecoration = "none";
		}
}

sideBlockControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0, 0));
}
